import {
	data
} from "uview-ui/libs/mixin/mixin";

const http = uni.$u.http;

// 获取天气
export function getWeatherInfo(data) {
	return http.get("/tools/getWeatherInfo", {
		params: {
			...data,
		},
	});
}


export function getNoticeList() {
	return http.get("/config/newNotice");
}

// 获取公告
export function getOssPolicy(data) {
	return http.get("/alOss/getPolicy", {
		custom: {
			showToast: false
		}
	});
}

// 获取隐私协议
export function getPrivacyAgreement() {
	return http.get("/config/PrivacyAgreement");
}

// 获取整改类型
export function getRectifyType(data) {
	return http.get("/config/RectifyType?state=1");
}

// 获取用户协议
export function getUserAgreement() {
	return http.get("/config/UserAgreement");
}

export function getUsersByAgentId() {
	const {
		orgId
	} = userInfo
	return http.get("/app/getUsersByAgentId", {
		params: {
			agentId: orgId,
		}
	});
}

export function getWaterMarkFile(data) {
	return http.post("/tools/addImgMark", data, {
		custom: {
			showToast: false
		}
	});
}
//获取实时录制水印
export function addVideoMark(data) {
	console.log(data)
	data.width = 1080
	return http.post("/tools/addVideoMark", data, {
		custom: {
			showToast: false
		}
	});
}
// 获取开工申请必看视频
export function getStartVideo() {
	return http.get("/config/getStartVideo");
}

export const getBaiduToken = () => {
	const client_id = 'GU6IiNHyC8tQ7PqdS3nDOr1t';
	const client_secret = 'CjyMjBHWf6H2cafhBoBLRTW6BGRUfViL';
	return new Promise((resolve, reject) => {
		uni.request({
			url: 'https://aip.baidubce.com/oauth/2.0/token', //仅为示例，并非真实接口地址。
			data: {
				grant_type: 'client_credentials',
				client_id,
				client_secret,
			},
			header: {
				'content-type': 'application/json;charset=utf-8' //自定义请求头信息
			},
			success: (res) => {
				// _this.token = res.data.access_token;
				resolve(res.data.access_token)
			},
			fail: (res) => {
				reject(res);
			}
		});
	})
}

export const baiduOcr = ({
	access_token,
	image
}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=${access_token}`, //仅为示例，并非真实接口地址。
			method: "POST",
			data: {
				image
			},
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				'accept': 'application/json'
			},
			success: (res) => {
				// _this.token = res.data.access_token;
				resolve(res.data)
			},
			fail: (res) => {
				reject(res);
			}
		});
	})
}

export const getFeishuToken = () => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: 'https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal', //仅为示例，并非真实接口地址。
			method: "POST",
			data: {
				app_id: "cli_a417f8404caf500c",
				app_secret: "kWW4Kb0ziHFOGJEphBUL8bniUFI5HTrX"
			},
			header: {
				'content-type': 'application/json;charset=utf-8' //自定义请求头信息
			},
			success: (res) => {
				// _this.token = res.data.access_token;
				resolve(res.data.app_access_token)
			},
			fail: (res) => {
				reject(res);
			}
		});
	})
}

export const feishuOcr = ({
	access_token,
	image
}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `https://open.feishu.cn/open-apis/optical_char_recognition/v1/image/basic_recognize`, //仅为示例，并非真实接口地址。
			method: "POST",
			data: {
				image
			},
			header: {
				'Content-Type': 'application/json; charset=utf-8',
				'Authorization': `Bearer ${access_token}`,
			},
			success: (res) => {
				// _this.token = res.data.access_token;
				resolve(res.data)
			},
			fail: (res) => {
				reject(res);
			}
		});
	})
}

// 实时录制指令
export function stopRealTimeRecord(data) {
	return http.post("/live/realTimeRecordCommand", data, {
		custom: {
			showToast: false
		}
	});
}

export function getSteamPushUrl(expireTime, markText) {
	return http.post("/live/getSteamPushUrl?expireTime=" + expireTime, markText, {
		custom: {
			showToast: false
		}
	});
}

export function getRecordOssPath(params) {
	return http.get(`/live/getRecordOssPath`, {
		params,
		custom: {
			showToast: false
		}
	});
}

export function getLiveAction(params) {
	return http.get('/live/getLiveAction', {
		params,
		custom: {
			showToast: false
		}
	});
}

export function checkOssAccess(url) {
	return new Promise((resolve, reject) => {
		uni.request({
			url,
			method: "HEAD",
			success: (res) => {
				resolve(res);
			},
		})
	})
}

export function getLiveCallback(params) {
	return http.get('live/getLiveCallback', {
		params,
		custom: {
			showToast: false
		}
	});
}
// 打开小程序
export function getWechatUrlLink() {
	return http.get('/wechat/getUrlLink')
}
